home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / gsmalloc.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  3.0 KB  |  82 lines

  1. /* Copyright (C) 1997, 1998, 1999 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: gsmalloc.h,v 1.2 2000/09/19 19:00:29 lpd Exp $ */
  20. /* Client interface to default (C heap) allocator */
  21. /* Requires gsmemory.h */
  22.  
  23. #ifndef gsmalloc_INCLUDED
  24. #  define gsmalloc_INCLUDED
  25.  
  26. /* Define a memory manager that allocates directly from the C heap. */
  27. typedef struct gs_malloc_block_s gs_malloc_block_t;
  28. typedef struct gs_malloc_memory_s {
  29.     gs_memory_common;
  30.     gs_malloc_block_t *allocated;
  31.     long limit;
  32.     long used;
  33.     long max_used;
  34. } gs_malloc_memory_t;
  35.  
  36. /* Allocate and initialize a malloc memory manager. */
  37. gs_malloc_memory_t *gs_malloc_memory_init(P0());
  38.  
  39. /* Release all the allocated blocks, and free the memory manager. */
  40. /* The cast is unfortunate, but unavoidable. */
  41. #define gs_malloc_memory_release(mem)\
  42.   gs_memory_free_all((gs_memory_t *)mem, FREE_ALL_EVERYTHING,\
  43.              "gs_malloc_memory_release")
  44.  
  45. /*
  46.  * Define a default allocator that allocates from the C heap.
  47.  * (We would really like to get rid of this.)
  48.  */
  49. extern gs_malloc_memory_t *gs_malloc_memory_default;
  50. extern gs_memory_t *gs_memory_t_default;  /* may be locked */
  51. #define gs_memory_default (*gs_memory_t_default)
  52.  
  53. /*
  54.  * The following procedures are historical artifacts that we hope to
  55.  * get rid of someday.
  56.  */
  57. gs_memory_t * gs_malloc_init(P0());
  58. void gs_malloc_release(P0());
  59. #define gs_malloc(nelts, esize, cname)\
  60.   (void *)gs_alloc_byte_array(&gs_memory_default, nelts, esize, cname)
  61. #define gs_free(data, nelts, esize, cname)\
  62.   gs_free_object(&gs_memory_default, data, cname)
  63.  
  64. /* Define an accessor for the limit on the total allocated heap space. */
  65. #define gs_malloc_limit (gs_malloc_memory_default->limit)
  66.  
  67. /* Define an accessor for the maximum amount ever allocated from the heap. */
  68. #define gs_malloc_max (gs_malloc_memory_default->max_used)
  69.  
  70. /* ---------------- Locking ---------------- */
  71.  
  72. /* Create a locked wrapper for a heap allocator. */
  73. int gs_malloc_wrap(P2(gs_memory_t **wrapped, gs_malloc_memory_t *contents));
  74.  
  75. /* Get the wrapped contents. */
  76. gs_malloc_memory_t *gs_malloc_wrapped_contents(P1(gs_memory_t *wrapped));
  77.  
  78. /* Free the wrapper, and return the wrapped contents. */
  79. gs_malloc_memory_t *gs_malloc_unwrap(P1(gs_memory_t *wrapped));
  80.  
  81. #endif /* gsmalloc_INCLUDED */
  82.